import router from "@/router/index";

router.beforeEach((to,from,next)=>{
    let token=window.sessionStorage.getItem("token");

    const whiteList=['/login']
    if(token){//有token表明已经登入了
        if(to.path==='/login'){//如果是登入请求则重定向到首页
            next('/')
        }else{//不是登入请求就放行
            next();
        }
    }else{//没token表明没登入
        if(whiteList.includes(to.path)){
            next();
        }else{
            next('/login');
        }
    }
})